<?php
 
use_helper('Javascript');
 
function zonedate($layout, $daylightsaving, $date2)
{
$countryzone=8;
if ($daylightsaving){

$daylight_saving = date('I');
if (!$daylight_saving){$zone=3600*($countryzone);} 
}
else {
   if ($countryzone>>0){$zone=3600*$countryzone;}
       else {$zone=0;}
}


//$date=gmdate($layout, strtotime($date2) + $zone);
$date=$date2;
return $date;
} 

function link_to_user_interested($user, $customerid)
{

  if ($user->isAuthenticated())
  {
	$idx = substr(strrev($_SESSION['customer_id']),0,1);
	$c = new Criteria();
    switch($idx){
    	case '0':
    		$c->add(ContactPeer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = ContactPeer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrpPeer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrpPeer::doSelect($c);
    		break;
    	case '1':
    		$c->add(Contact1Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact1Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp1Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp1Peer::doSelect($c);
    		break;
    	case '2':
    		$c->add(Contact2Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact2Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp2Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp2Peer::doSelect($c);
    		break;;
    	case '3':
    		$c->add(Contact3Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact3Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp3Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp3Peer::doSelect($c);
    		break;
    	case '4':
       		$c->add(Contact4Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact4Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp4Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp4Peer::doSelect($c);
    		break;
    	case '5':
    		$c->add(Contact5Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact5Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp5Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp5Peer::doSelect($c);
    		break;
    	case '6':
    		$c->add(Contact6Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact6Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp6Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp6Peer::doSelect($c);
    		break;
    	case '7':
    		$c->add(Contact7Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact7Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp7Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp7Peer::doSelect($c);
    		break;
    	case '8':
    		$c->add(Contact8Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact8Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp8Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp8Peer::doSelect($c);
    		break;
    	case '9':
    		$c->add(Contact9Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested = Contact9Peer::doSelect($c);
    		$c = new Criteria();
    		$c->add(CnttCnttgrp9Peer::CUSTOMER_ID, $_SESSION['customer_id']);
    		$interested2 = CnttCnttgrp9Peer::doSelect($c);
    		break;
    }
    
   
    if (!$interested && !$interested2)
    {
      // already interested
      return '';
    }
    else
    {
      // didn't declare interest yet
      return link_to_remote('Select From Phone Book', array(
        'url'      => 'sendsms/loadphone?id='.$customerid,
        'update'   => array('success' => 'block_'.$customerid),
        'loading'  => "Element.show('indicator')",
        'complete' => "Element.hide('indicator');".visual_effect('highlight', 'mark_'.$customerid),
      ));
    }
  }
  else
  {
    return link_to('interested?', 'user/login');
  }
  
  //for save message as template  
}

function link_to_save_message($customerid)
{ 	
	return link_to_remote('Save', array(		
        'url'      => 'sendsms/message',
        //'update'   => array('success' => 'good'),
        'loading'  => "Element.show('indicator1')",
        'complete' => "Element.hide('indicator1');".visual_effect('highlight1', 'cool'),
      ));
  	//return submit_to_remote('ajax_submit', 'Add in AJAX', array(
      	//'url'      => 'sendsms/message?customerid='.$customerid.'&msgtemplatetext='.$msg,
		//'update'   => 'txtmessagebody',      	
		//'confirm'  => 'Are you sure?',
      	//));	
}


function link_to_user_template($user, $customerid)
{
  //for save message as template
  echo submit_to_remote('ajax_submit', 'Save as template', array(
      //'update'   => 'sendsms/loadphone1?id='.$customerid,
      'url'      => 'sendsms/template',
	  'loading'  => "Element.show('load')",
      'complete' => "Element.hide('load')",
  ));
}

function link_to_user_test($user, $customerid)
{
      return link_to_remote('Testing http box2', array(
        'url'      => 'report/testing',
        'update'   => array('success' => 'block_individual'),
        'loading'  => "Element.show('indicator')",
        'complete' => "Element.hide('indicator');".visual_effect('highlight', 'mark_individual'),
      ));
}
?>